package ysq.xyg.host.controller;

import ysq.xyg.base.aspect.BaseLog;
import ysq.xyg.base.util.BaseConstant;

import cn.hutool.core.util.StrUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import ysq.xyg.base.aspect.BaseLog;
import ysq.xyg.base.controller.BaseController;
import ysq.xyg.base.util.BaseConstant;
import ysq.xyg.base.model.dto.ReturnEntity;
import ysq.xyg.host.model.po.HostItemSubscription;
import ysq.xyg.host.model.vo.HostItemSubscriptionVo;
import ysq.xyg.host.service.HostItemSubscriptionService;

import javax.servlet.http.HttpServletRequest;

/**
 * 房产模块-动态订阅controller层
 *
 * @author congcong tao
 * @date 2020-3-6 10:12:54
 */
@RestController
public class HostItemSubscriptionController extends BaseController {

    private static Logger log = LoggerFactory.getLogger(HostItemSubscriptionController.class);

    @Autowired
    private HostItemSubscriptionService hostItemSubscriptionService;

    /**
     * 分页查询
     *
     * @param hostItemSubscriptionVo 对象
     * @param pageSize 展示数量
     * @param pageNum 当前页面
     * @author congcong tao
     * @date 2020-3-6 10:12:54
     */
    @BaseLog(module = "房产模块", className = "动态订阅",methods = "分页查询", businessType = BaseConstant.SYS_BUSINESS_TYPE_GET, operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/hostItemSubscription/page",method = RequestMethod.POST)
    public ReturnEntity page(HostItemSubscriptionVo hostItemSubscriptionVo, int pageSize, int pageNum){
        ReturnEntity returnEntity = hostItemSubscriptionService.page(hostItemSubscriptionVo, pageSize, pageNum);
        return returnEntity;
    }

    /**
     * 跳转连接
     *
     * @param id 主键id
     * @author congcong tao
     * @date 2020-3-6 10:12:54
     */
    @RequestMapping(value = "/hostItemSubscription/getEntity", method = RequestMethod.GET)
    public ModelAndView getEntity(String id) {
        ModelAndView view = new ModelAndView("/host/hostItemSubscriptionUpdateOrSave");
        if (StrUtil.isNotEmpty(id)) {
            HostItemSubscription hostItemSubscription = hostItemSubscriptionService.selectByPrimaryKey(id);
            view.addObject("hostItemSubscription", hostItemSubscription);
        }
        return view;
    }

    /**
     * 删除
     *
     * @param id 主键id
     * @author congcong tao
     * @date 2020-3-6 10:12:54
     */
    @BaseLog(module = "房产模块", className = "动态订阅", methods = "删除", businessType = BaseConstant.SYS_BUSINESS_TYPE_DELETE, operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/hostItemSubscription/delete")
    public ReturnEntity delete(HttpServletRequest request, String id){
        return hostItemSubscriptionService.delete(id, acceptCurrentUser(request));
    }

    /**
     * 添加或修改
     *
     * @param hostItemSubscriptionVo Vo对象
     * @author congcong tao
     * @date 2020-3-6 10:12:54
     */
    @BaseLog(module = "房产模块", className = "动态订阅", methods = "添加或修改", businessType = BaseConstant.SYS_BUSINESS_TYPE_UPDATE, operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/hostItemSubscription/addOrUpdate", method = RequestMethod.POST)
    public ReturnEntity delete(HttpServletRequest request, HostItemSubscriptionVo hostItemSubscriptionVo){
        return hostItemSubscriptionService.addOrUpdate(hostItemSubscriptionVo, acceptCurrentUser(request));
    }
}